# 类作为装饰器

class ClassDecorator:
    """类装饰器"""
    def __init__(self, func):
        self.func = func
        self.call_count = 0

    def __call__(self, *args, **kwargs):
        self.call_count += 1
        print(f"📊 第 {self.call_count} 次调用 {self.func.__name__}")
        return self.func(*args, **kwargs)

@ClassDecorator
def calculate_sum(a, b):
    return a + b

print(calculate_sum(1, 2))
print(calculate_sum(3, 4))



class LoggingDecorator:
    """带参数的类装饰器"""
    def __init__(self, level="INFO"):
        self.level = level

    def __call__(self, func):
        def wrapper(*args, **kwargs):
            print(f"[{self.level}] 调用函数: {func.__name__}")
            result = func(*args, **kwargs)
            print(f"[{self.level}] 函数执行完成")
            return result
        return wrapper

@LoggingDecorator(level="DEBUG")
def debug_function():
    print("调试函数执行中")

@LoggingDecorator(level="ERROR")
def error_function():
    print("错误处理函数执行中")

debug_function()
error_function()